package edu.faytechcc.csc.gui;

import edu.faytechcc.csc.business.Model;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

/**
 * Represents the portion of the main GUI that retrieves information from the 
 * user about where to store the completed files after the batch process
 * @author Charles Bryan
 */
public class DestinationPanel extends JPanel
{

    private FileChooserPanel chooser;

    public DestinationPanel()
    {
        chooser = new FileChooserPanel("Destination Directory:", 25);
        this.chooser.setFileSectionMode(JFileChooser.DIRECTORIES_ONLY);
        this.chooser.setToolTipText("Select the directory that you want to  "
                + "completed zips to go to.");
        this.add(this.chooser);
    }

     /**
     * Returns an empty string and sets the correct field in the Model, model,
     * if the user has entered correct data, otherwise, this method returns 
     * a String with an error message in it.
     * 
     * @param model The Model to set the fields in
     * @return Empty string if all goes well, an error message as a String if 
     * not.
     */
    public String getText(Model model)
    {
        String result = "";
        if (chooser.isEmpty())
        {
            result += "Destination Directory feild is empty.\n";
            this.chooser.setWarningColor(true);
        }
        else
        {
            try
            {
                model.setDestination(this.chooser.getText());
            }
            catch (Exception e)
            {
                result += "Destination Directory does not allow changes.\n";
                this.chooser.setWarningColor(true);
            }
        }
        return result;
    }
}
